/*
 * Copyright (c) 2018-2023 北京华恒盛世科技有限公司
 * QUICKPOOL is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
*/

#ifndef _RES_REQ_H_
#define _RES_REQ_H_

#include "quickpool.h"

#define REQ_SELECT      0x01
#define REQ_ORDER       0x02
#define REQ_RUSAGE      0x04
#define REQ_FILTER      0x08
#define REQ_TYPE 0x10
#define REQ_SPAN        0x20
#define REQ_AFFINITY    0x40

#define REQ_ALL         REQ_SELECT | REQ_ORDER | REQ_RUSAGE | REQ_SPAN | REQ_AFFINITY

#define PARSE_BAD_EXP  -1
#define PARSE_BAD_NAME -2
#define PARSE_BAD_VAL  -3
#define PARSE_BAD_FILTER  -4
#define PARSE_ERROR_MEMORY -5

#define TYPE_PU             0x01
#define TYPE_CPUBIND        0x02 
#define TYPE_MEMBIND        0x04
#define TYPE_DISTRIBUTE     0x08 

#define SCOPE_INTASK    1
#define SCOPE_INTJOB    2
#define SCOPE_ALLJOBS   3

typedef enum {
    BIND_TYPE_NUMA=1,
    BIND_TYPE_SOCKET,
    BIND_TYPE_CORE,
    BIND_TYPE_THREAD,
} cpubind_t;

typedef enum {
    MEMBIND_ONLY=1,
    MEMBIND_PREFER,
} membind_t;

typedef struct affinity_exclusive {
    cpubind_t level;
    unsigned int scope;
} exclusive_t;

struct requirement {
    char *select;
    unsigned int num_order;
    int order[NUMBUILTIN];
    float *val;
    unsigned int num_index;
    int *indicies;
    int *rusage_bit_map;
    unsigned int duration;
    float decay;
    unsigned int num_host;
    unsigned int max_num_host;
    unsigned int ptile;
    unsigned int options;
    unsigned int sizeof_select;
    char **select_array;
    LIST_T *req_list;
    cpubind_t same;
    exclusive_t exclusive;
    unsigned int num_bind;
    unsigned int bind_type;
    cpubind_t cpubind_type;
    membind_t membind_type; 
};

struct resrsv {
    LIST_T *forw;
    LIST_T *back;
    int *bitmap;
    float *val;
};

#endif
